import {
  InDB
} from './indb.js'
import enSTrackStateData from '../data/enSTrackStage.js'
import enShearerRunnerCode from '../data/enShearerRunnerCode.js'
import enAutoActCode from "../data/enAutoActCode.js"

var DB_NAME = "controller"
var DB_VERSION = 1
var DB_Setting = {
  name: DB_NAME,
  version: DB_VERSION,
  stores: [{
      name: 'RunnersID',
      keyPath: 'id',
      autoIncrement: true,
    }, {
      name: 'AutoActCode',
      keyPath: 'id',
      autoIncrement: true,
    },
    // {
    //   name: "CfgCombineControlDefine",
    //   keyPath: "id",
    //   autoIncrement: true,
    // },
    {
      name: "STrackStages",
      keyPath: "id",
      autoIncrement: true,
    },
    {
      name: "enSTrackState",
      keyPath: "id",
      autoIncrement: true,
    }, {
      name: "actionsPool",
      keyPath: "STrackID",
      autoIncrement: true,
    },
    {
      name: "CfgSTrackControl",
      keyPath: "id",
      autoIncrement: true,
    },
    {
      name: "controllerTools",
      keyPath: "tools_id",
      autoIncrement: true,
    },
    {
      name: "CfgSTrackRunner",
      keyPath: "id",
      autoIncrement: true,
    }, {
      name: "CfgCombineControlDefine",
      keyPath: "id",
      autoIncrement: true,
    },
    {
      name: "defineTools",
      keyPath: "tool_id",
      autoIncrement: true,
    }, {
      name: "CfgActionElment",
      keyPath: "id",
      autoIncrement: true,
    },

  ],
}
var idb = new InDB(DB_Setting)
var RunnersID = idb.use('RunnersID')
insertDefaultData(enSTrackStateData, RunnersID)
var enSTrackState = idb.use("enSTrackState")
var STrackStages = idb.use("STrackStages")
insertDefaultData(enSTrackStateData, enSTrackState)

var actionsPool = idb.use('actionsPool')
insertDefaultData(enShearerRunnerCode, actionsPool)
var CfgSTrackControl = idb.use('CfgSTrackControl')
var controllerTools = idb.use('controllerTools')
var CfgSTrackRunner = idb.use('CfgSTrackRunner')
var CfgCombineControlDefine = idb.use('CfgCombineControlDefine')
var CfgSTrackRunner = idb.use('CfgSTrackRunner')
var CfgActionElment = idb.use('CfgActionElment')
var AutoActCode = idb.use('AutoActCode')
insertDefaultData(enAutoActCode, AutoActCode)
var defineTools = idb.use('defineTools')
async function insertDefaultData(data, store) {
  let count = await store.count()
  if (count == 0) {
    for (let key in data) {
      await store.add({
        key: key,
        name: data[key].name,
        value: data[key].key,
      })
    }
  }
}
export default {
  RunnersID: RunnersID,
  enSTrackState: enSTrackState,
  STrackStages: STrackStages,
  actionsPool: actionsPool,
  CfgSTrackControl: CfgSTrackControl,
  controllerTools: controllerTools,
  CfgSTrackRunner: CfgSTrackRunner,
  CfgCombineControlDefine: CfgCombineControlDefine,
  CfgActionElment: CfgActionElment,
  defineTools: defineTools,
  AutoActCode: AutoActCode
}
